#include <bits/stdc++.h>

using namespace std;
using ll = long long;

ll gcd(vector<ll> v)
{
    return __gcd(__gcd(v[0], v[1]), v[2]);
}

void solve()
{
    int n, h;
    cin >> n >> h;
    vector<vector<ll>> v(n, vector<ll>(3));
    for (int i = 0; i < n; i++)
        cin >> v[i][0] >> v[i][1] >> v[i][2];
    for (int i = 0; i < n; i++)
    {
        v[i][2] += 2 * (h - v[i][2]);
        ll g = gcd(v[i]);
        v[i][0] /= g;
        v[i][1] /= g;
        v[i][2] /= g;
    }
    for (int i = 0; i < n; i++)
        cout << v[i][0] << ' ' << v[i][1] << ' ' << v[i][2] << endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}